@import "./var.scss";
@import "../../../styles/mixin.scss";

$iteration: 12;
$blade-rotation: 0deg;
$animation-delay: -1.1s;

:host {
  font-size: 0;
  line-height: 1;
}

@mixin blade-loop($rotation, $delay) {
  @for $i from 1 to $iteration {
    &:nth-child(#{$i}) {
      transform: rotate(($i * (360deg / 12)));
      animation-delay: $delay + $i * 0.1s;
    }
  }
}

@include b(spin) {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  &__icon {
    height: $spin-icon-size;
    width: $spin-icon-size;
  }

  &--circular {
    width: 100%;
    height: 100%;
    border: 3px solid;
    border-radius: 100%;
    border-color: currentColor;
    border-top-color: transparent;
    box-sizing: border-box;
    animation: spin $spin-circular-animation-duration infinite linear;
  }

  &--spinner {
    position: relative;
    width: 100%;
    height: 100%;
    vertical-align: top;
  }

  &__blade {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    animation: spin-fade $spin-spinner-animation-duration linear infinite;

    &::after {
      position: absolute;
      display: block;
      content: "";
      left: 50%;
      min-width: 2px;
      width: 10%;
      min-height: 5px;
      height: 25%;
      background-color: currentColor;
      border-radius: 20%;
      transform: translateX(-50%);
    }

    @include blade-loop($blade-rotation, $animation-delay);
  }

  &--vertical {
    flex-direction: column;

    @include e(text){
      margin: $spin-text-margin 0 0 0;
    }
  }

  &__text {
    color: $spin-text-color;
    font-size: $spin-text-size;
    margin-left: $spin-text-margin;

    &:empty {
      display: none;
    }
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes spin-fade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
